package com.expert.conrtoller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.expert.annotations.RoleAnnotation;
import com.expert.dto.AddMenuDTO;
import com.expert.dto.UpdateMenuDTO;
import com.expert.enums.RoleLevel;
import com.expert.pojo.Menu;
import com.expert.result.Result;
import com.expert.service.MenuService;
import com.expert.vo.MenuVo;
import com.expert.vo.ParentMenuVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: MenuController
 * @Author: cxs
 * @Date: 2024/03/05 13:29
 * @Description:
 **/
@RestController
@RequestMapping("/menu")
@Slf4j
public class MenuController {

    @Autowired
    MenuService menuService;
    @RoleAnnotation(level = RoleLevel.SUPER)
    @GetMapping("/page")
    public Result<Page<Menu>> pageMenu(Integer page, Integer pageSize,String title,String pTitle){
        log.info("分页查询菜单信息");
      Page<Menu> menuPage = this.menuService.pageMenu(page,pageSize,title,pTitle);
      return Result.success(menuPage);
    }
    @RoleAnnotation(level = RoleLevel.SUPER)
    @GetMapping("/getSystemMenu")
    public Result<List<MenuVo>> getSystemMenu(){
        log.info("获取系统完整菜单信息");
       List<MenuVo> systemMenus = this.menuService.getSystemMenus();
        return Result.success(systemMenus);
    }

    @RoleAnnotation(level = RoleLevel.SUPER)
    @GetMapping("/parent")
    public  Result<List<ParentMenuVo>> getParentMenu(){
        log.info("获取系统所有父级菜单信息");
        List<ParentMenuVo> parentMenus=this.menuService.getParentMenu();
        return Result.success(parentMenus);
    }
    @RoleAnnotation(level = RoleLevel.SUPER)
    @GetMapping("/{id}")
    public  Result<Menu> getMenuById(@PathVariable("id") Long id ){
        log.info("根据id获取菜单");
        Menu menu=this.menuService.getById(id);
        return Result.success(menu);
    }

    @RoleAnnotation(level = RoleLevel.SUPER)
    @PostMapping("/addMenu")
    public  Result addMenu(@RequestBody AddMenuDTO addMenuDTO ){
        log.info("添加菜单");
        this.menuService.addMenu(addMenuDTO);
        return Result.success();
    }

    /**
     * 删除菜单
     * @param ids
     * @return
     */
    @RoleAnnotation(level = RoleLevel.SUPER)
    @DeleteMapping("/deleteMenu")
    public  Result deleteMenu(@RequestParam ArrayList<Long> ids ){
        log.info("删除菜单：{}",ids);
        this.menuService.deleteMenu(ids);
        return Result.success();
    }
    /**
     * 修改菜单
     * @param updateMenuDTO
     * @return
     */
    @RoleAnnotation(level = RoleLevel.SUPER)
    @PutMapping("/updateMenu")
    public  Result updateMenu(@RequestBody UpdateMenuDTO updateMenuDTO ){
        log.info("修改菜单：{}",updateMenuDTO);
        this.menuService.updateMenu(updateMenuDTO);
        return Result.success();
    }
}
